import { objDeepCopy,getDateString } from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.getAllSaleorderList(this);
		this.getSaleorderselect(this);
	},
	mounted() {
		
	},
	activated() {
		this.getAllSaleorderList(this);
	},
	methods: {
		//获取列表接口
		getAllSaleorderList(that,params,pageIndex = 1,pageSize = 10) {
			params = params || {businessType:120};
			this.$ajax({
				method: 'post',
				url:this.apiTest+'/supplier/whWarehouse/outStorageOrder/list',
				//url:'/api/whWarehouse/outStorageOrder/list',
				data:{
					condition:params,
					pageIndex: pageIndex,
					pageSize: pageSize,
				}
			}).then((res)=>{
				that.Model.tableData = [];
				var data = res.data;
				if(data.status == 200){
					var obj = {};
					var pagination = commonObject.paginationFunction(data.result);
					that.Model.paginationObject = objDeepCopy(pagination);
					var result = data.result.result;
					console.log(result)
					if(result){
						for (var i = 0; i < result.length; i++) {
							obj = objDeepCopy(result[i]);
							console.log(obj);
							that.Model.tableData.push(obj);
						}
					}
				}else{
					that.tips(that,'warning',data.msg)
				}
			
			});
		},
		//下拉框
		getSaleorderselect(that) {
			this.$ajax({
				method: 'get',
				url:this.apiTest+'/supplier/whWarehouse/outStorageOrder/orderBox?parentId=211',
				//url:'/api/whWarehouse/outStorageOrder/orderBox?parentId=211',
			}).then((res)=>{
				var data = res.data;
				if(data.status == 200){
					var result = data.result;
					 console.log(result)
					this.Model.filterOptionData = result;
					let platFormArr = [], wareHouseTypeArr = [], originChannelArr = [], wareHouseStatusArr = [], isSignArr = [], isTicketArr = [];
					for (let i in result.platForm) {//发货平台
						platFormArr.push({ label: result.platForm[i], value: i });
					};
					for (let i in result.wareHouseType) {//出库单类型
						wareHouseTypeArr.push({ label: result.wareHouseType[i], value: i });
					};
					for (let i in result.originChannel) {//来源渠道
						originChannelArr.push({ label: result.originChannel[i], value: i });
					};
					for (let i in result.wareHouseStatus) {//出库单状态
						wareHouseStatusArr.push({ label: result.wareHouseStatus[i], value: i });
					};
					for (let i in result.isSign) {//签名
						isSignArr.push({ label: result.isSign[i], value: i });
					};
					for (let i in result.isTicket) {//开票
						isTicketArr.push({ label: result.isTicket[i], value: i });
					};
					this.Model.filterOption.items[1].data = platFormArr;//发货平台
					this.Model.filterOption.items[2].data = wareHouseTypeArr;//出库单类型
					this.Model.filterOption.items[3].data = originChannelArr;//来源渠道
					this.Model.filterOption.items[4].data = wareHouseStatusArr;//出库单状态
					this.Model.filterOption.items[5].data = isSignArr;//签名
					this.Model.filterOption.items[6].data = isTicketArr;//开票
					this.Model.defaultFilterOption = _.cloneDeep(this.Model.filterOption);
				}else{
					that.tips(that,'warning',data.msg)
				}
			
			});
		},
		//跳转详情
		tableDetail(row,flag,status) {
			this.$router.push({
				path:'afterSaleLeaveStoreDetail',
				query: {
					id:row.id,
					flag,
					status
				}
			});
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		//点击开票
		OpenInvoice(row,type) {
			var that = this;
			this.$confirm('是否确认'+type+'?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
			}).then(() => {
				that.ToInvoice(that,row.id)
			}).catch(() => {
				that.$message({
					type: 'info',
					message: '已取消'+type
				}); 
			});	
		},
		//操作——出库
		Outofstock(that,id) {
			this.$ajax({
				method: 'get',
				url:this.apiTest+'/supplier/whWarehouse/outStorageOrder/cancel/'+id,
			}).then((res)=>{
				console.log(res);
				var data = res.data;
				if(data.status == 200){
					that.getAllsoledList(that);
					that.tips(that,'success','操作成功');
				}else{
					that.tips(that,'warning',data.msg);
				}
			});
		},
		//操作——开票
		ToInvoice(that,params) {
			this.$ajax({
				method: 'get',
				url:this.apiTest+'/supplier/whWarehouse/outStorageOrder/invoice',
				data:params
			}).then((res)=>{
				console.log(res);
				var data = res.data;
				if(data.status == 200){
					this.Model.InvoiceVisible = true;
				}else{
					that.tips(that,'warning',data.msg);
				}
			});
		},
		//操作——作废
		Tovoid(row,type) {
			var that = this;
			this.$confirm('作废该入库单后，则无法再对该单进行操作，是否确认'+type+'?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
			}).then(() => {
				console.log(row)
			}).catch(() => {
				that.$message({
					type: 'info',
					message: '已取消'+type
				}); 
			});	
		},
		//确认红冲
		sureRedinvoice() {
			
		},
		handleSelectionChange(val) {
			console.log(val);
		},
		handleCurrentChange(val) {
			var searchFromData = this.Model.searchFromData;
			this.getAllSaleorderList(this,searchFromData,val);
		},
		handleSizeChange(val) {
			var searchFromData = this.Model.searchFromData;
			this.getAllSaleorderList(this,searchFromData,undefined,val);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = {
				businessType:120,
				keyWord:val.keyword,
				deliveryPlatform:val.deliveryPlatform,
				orderType:val.orderType,
				originChannel:val.originChannel,
				billStatus:val.billStatus,
				isSign:val.isSign,
				isInvoice:val.isInvoice
			}
			if(val.createTime){
				this.Model.searchFromData.createStartTime = getDateString(val.createTime[0]);
				this.Model.searchFromData.createEndTime = getDateString(val.createTime[1]);
			}
			if(val.outStorageTime){
				this.Model.searchFromData.outStorageStartTime = getDateString(val.outStorageTime[0]);
				this.Model.searchFromData.outStorageEndTime = getDateString(val.outStorageTime[1]);
			}
			console.log(this.Model.searchFromData)
		},
		toSearch(val) {
			var searchFromData = this.Model.searchFromData;
			this.getAllSaleorderList(this,searchFromData);
		},
		toClear(val) {
			this.Model.searchFromData = _.cloneDeep(this.Model.defaultSearchFromData);
			this.Model.filterOption = _.cloneDeep(this.Model.defaultFilterOption);
		},
		toExport(val) {
			console.log(val);
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
	}
}
export default Controller;